#!/usr/bin/python3.5

# -*- coding: utf-8 -*-

def threeSumSmaller(nums, target):

     n = len(nums)
     if n<3:
         return 0
     nums.sort()
     # res =[]
     all=0
     i = 0
     while i< n-2:
         k = i+1
         m = n-1
         while k < m:
             sum3 = nums[i]+ nums[k] + nums[m]
             if sum3 < target:
                 # for s in range(k,m) :
                     # res.append([nums[i], nums[s],nums[m]])
                 all+= (m-k)
                 break
             else:
                 m-=1
         i+=1
         while i< n-2 and nums[i]==nums[i-1]:
             i+=1
     return all


if __name__ == '__main__':
        # arr=[int(x) for x in input().strip().split(' ')]
        arr = [-2, 0, 1, 3]
        target = 2

        a = threeSumSmaller(arr, target)
        print(a)

